# -*- encoding: utf-8 -*-
'''
@Time    :   2021/01/05 19:33:54
@Author  :   lyc
@Email   :   lyc0209@qq.com
@FileName:   Curtain.py
'''

import RPi.GPIO as GPIO
import time

ENA = 16
IN1 = 20
IN2 = 21

def close_curtain():
    GPIO.output(ENA, GPIO.HIGH)
    GPIO.output(IN1, GPIO.HIGH)
    GPIO.output(IN2, GPIO.LOW)

def open_curtain():
    GPIO.output(ENA, GPIO.HIGH)
    GPIO.output(IN1, GPIO.LOW)
    GPIO.output(IN2, GPIO.HIGH)

def test():
    GPIO.output(16, GPIO.HIGH)
    GPIO.output(20, GPIO.HIGH)
    GPIO.output(21, GPIO.LOW)

def init():
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(ENA,GPIO.OUT)
    GPIO.setup(IN1,GPIO.OUT)
    GPIO.setup(IN2,GPIO.OUT)



def reset():
    GPIO.output(16, GPIO.LOW)
    GPIO.output(20, GPIO.LOW)
    GPIO.output(21, GPIO.LOW)

def open_close_curtain(light):
    init()
    if light == "1":
        open_curtain()
    elif light == "0":
        close_curtain()
    time.sleep(40)
    reset()


if __name__ == "__main__":
    init()
    # test()
    open_curtain()
    time.sleep(40)
    reset()
    # GPIO.cleanup()
